package org.sjsu.freedoor.service;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.sjsu.freedoor.model.*;


@Path("")

public class CommunityService {
	
	@GET
	@Path("communities")
	@Produces(MediaType.TEXT_PLAIN)
	public Response getCommunities() {

		Freedoor fd = Freedoor.getInstance();
		String msg = fd.getCommunities().toJSON();

		
		System.out.println(msg);

		return Response.ok(msg, MediaType.TEXT_PLAIN).build();
	}
	
	@POST
	@Path("communities")
	@Produces(MediaType.TEXT_PLAIN)
	@Consumes(MediaType.APPLICATION_JSON)
	public Response postCommunities(String body) {

		String msg = "TRUE";
			
		Freedoor fd = Freedoor.getInstance();
		boolean ret = fd.postCommunities(body);

		if(ret == true)
			msg = "TRUE";
		else
			msg = "FALSE";
		
		return Response.ok(msg, MediaType.TEXT_PLAIN).build();
		
	}


}
